<html>
<head>
 <meta charset="UTF-8">
<title>注册</title>
<link rel="stylesheet" type="text/css" href="./css/regist_styles.css">

	<script src="client_modules/jquery/dist/jquery.js"></script>
	<script src="client_modules/angular/angular.js"></script>
	<script src="client_modules/ng-file-upload-shim/ng-file-upload.js"></script>
	<script src="client_modules/ng-file-upload/ng-file-upload.js"></script>



</head>


<body ng-app="mainApp" ng-controller="RegistController">

<div class="htmleaf-container">
	<div class="wrapper">
		<div class="container">
			<h1>注册</h1>

			<form  class="form">
				<table	>
					<tr><td><input required="required" type="text" placeholder="用户名" ng-model="cu.account" id="username"><div >{{cu.tip}}</div></td></tr>
					<tr><td><input required="required" type="password" placeholder="密码" ng-model="cu.password" id="password"></td></tr>
					<tr><td><input required="required" type="text" placeholder="店名" ng-model="cu.shopName"></td></tr>
					<tr><td><input required="required" type="text" placeholder="地址" ng-model="cu.address"></td></tr>
					<tr><td>
						<button class="uploadBtn" type="file" ngf-select="uploadFiles($file, $invalidFiles)" accept="image/*" ngf-max-height="1000" ngf-max-size="10MB">{{img}}</button>
						</td></tr>
					<tr><td><button class="regist-button" ng-disabled="ss" ng-click="submit()">注册</button></td></tr>
				</table>
					<a href="merchantLogin1.html" class="login">登录</a>
			</form>
		</div>



	</div>
</div>


</body>

<script>
	var regist=angular.module("mainApp",['ngFileUpload']);
	regist.controller("RegistController",['$scope','Upload','$timeout','$http',function ($scope,Upload,$timeout,$http) {
		$scope.cu={};
		$scope.ss=1;
		$scope.img="选择图片";
		$scope.$watch("cu.account",function (n,o) {
			var req={
				method:"GET",
				url:"merchant?account="+n
			}
			$http(req)
					.then(function(res){
						if(res.data=="y"){
							$scope.cu.tip="用户名已存在";
						}else{
							$scope.cu.tip="";
						}
					});
		});

		$scope.uploadFiles=function(file,errFiles){

			$scope.f=file;
			$scope.cu.icon=$scope.f.name;

			$scope.errFiles=errFiles&&errFiles[0];

			if(file){

				file.upload=Upload.upload({
					url:'uploads',
					data:{file:file}
				});

				file.upload.then(function(response){
					$timeout(function(){
						$scope.img="上传成功";
						$scope.ss=null;
						file.result=response.data;
					});
				},function(response){
					if(response.status>0)
						$scope.errorMsg=response.status+':'+response.data;


				},function(evt){
					file.progress=Math.min(100,parseInt(100.0*evt.loaded/evt.total));
				});

			}


		}






		$scope.submit=function(){
			var req={
				method:"POST",
				url:"merchant",
				data:$scope.cu,
				headers:{"Content-type":"application/json"}
			};

			$http(req)
					.then(function(res){
						if(res.data.account){
							window.location.href = "merchantLogin1.html";
						}
					});
		}


	}]);






</script>


</html>